from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    # 初始化驱动
    def __init__(self,driver):
        self.driver = driver

    def open_url(self,url):
        """打开浏览器"""
        self.driver.get(url)

    def find_element(self,loc):
        """定位元素方法"""
        # 显示等待
        WebDriverWait(self.driver,20,0.5).until(EC.presence_of_element_located(loc))
        return self.driver.find_element(*loc)

    def click(self,loc):
        """点击操作"""
        self.find_element(loc).click()

    def send_keys(self,loc,text):
        """键盘输入操作"""
        self.find_element(loc).send_keys(text)

    def get_text(self,loc):
        """获取文本"""
        return self.find_element(loc).text

    def scroll_di(self,x):
        """滚动到指定像素"""
        self.driver.execute_script(f'window.scrollTo(0,{x})')


